how do loops work in javascript